package org.rohmh;

import java.util.Collection;

import org.rohmh.security.domain.Users;
import org.rohmh.user.UserController;
import org.rohmh.user.domain.Address;
import org.rohmh.user.domain.Member;
import org.rohmh.user.service.MemberService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


/**
 * Handles requests for the application welcome page.
 */
@Controller
@RequestMapping("/main")
public class MainController {

	private Logger logger = org.slf4j.LoggerFactory.getLogger(UserController.class);

    @Autowired
    private MemberService userService;
    
    private Member member;
    
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public void versionMain(ModelMap model) {
		logger.info("version 1.1 main!");
    	// userService.remove(user);
	}

	@RequestMapping(value = "/usertest", method = RequestMethod.GET)
	public void userTest(ModelMap model) {
		logger.info("Welcome!");
		
    	Address address = new Address("Evergreen Terrace", "99a", "Springfield", "57657", "Ohio", "USA");
    	member = new Member( new Users("testid", "testpassword", true));
    	member.setFirstName("firstName");
    	member.setMiddleName("middleName");
    	member.setLastName("lastName");
    	member.setEmailAddress("someone@gmail.com");
    	member.setPhoneNumber("1234567891");
    	member.setAddress(address);
		
    	userService.persist(member);
    	model.addAttribute("user", member);
    	// userService.remove(user);
	}
}
